package org.jetlinks.community.mstn.term;

import org.hswebframework.ezorm.core.param.Term;
import org.hswebframework.ezorm.rdb.metadata.RDBColumnMetadata;
import org.hswebframework.ezorm.rdb.operator.builder.fragments.PrepareSqlFragments;
import org.hswebframework.ezorm.rdb.operator.builder.fragments.SqlFragments;
import org.hswebframework.ezorm.rdb.operator.builder.fragments.term.AbstractTermFragmentBuilder;
import org.springframework.stereotype.Component;

@Component
public class MstnTenantUserTermBuilder extends AbstractTermFragmentBuilder {
    public static final String tenantType = "mstn-tenant";

    public MstnTenantUserTermBuilder() {
        super(tenantType, "查询租户下用户");
    }

    @Override
    public SqlFragments createFragments(String columnFullName, RDBColumnMetadata rdbColumnMetadata, Term term) {
        PrepareSqlFragments fragments = PrepareSqlFragments.of();
        fragments
                .addSql("exists(select 1 from s_dimension_user sdu where su.id = sdu.user_id and sdu.dimension_id = " + columnFullName);
        return fragments;
    }
}
